/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.geergenbein.dao;

import org.unicode.unihan.dao.*;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.cedict.dao.CedictDAO;
import org.geergenbein.azw.dao.transcription.DialectDAOHibernate;
import org.geergenbein.azw.dao.transcription.TonedCodePointDAOHibernate;
import org.geergenbein.azw.dao.transcription.TonedTranscriptionDAOHibernate;
import org.geergenbein.azw.dao.transcription.TranscriptionSystemDAOHibernate;
import org.geergenbein.azw.dao.transcription.UntonedCodePointDAOHibernate;
import org.geergenbein.azw.dao.transcription.UntonedTranscriptionDAOHibernate;

/**
 * Singleton
 * @author andrew
 */
public class DAOUtils {

    private EntityManagerFactory emf;
    private EntityManager em;
    private UnihanRowDAO unihanRowDAO;
    private CedictDAO cedictDAO;
    private DialectDAOHibernate dialectDAO;
    private TonedCodePointDAOHibernate tonedCodePointDAO;
    private TonedTranscriptionDAOHibernate tonedTranscriptionDAO;
    private TranscriptionSystemDAOHibernate transcriptionSystemDAO;
    private UntonedCodePointDAOHibernate untonedCodePointDAO;
    private UntonedTranscriptionDAOHibernate untonedTranscriptionDAO;

    private final static DAOUtils instance = new DAOUtils();

    private DAOUtils() {
        emf = Persistence.createEntityManagerFactory("UHLibraryPU");
        em = emf.createEntityManager();
        unihanRowDAO = new UnihanRowDAO(em);
        cedictDAO = new CedictDAO(em);
        dialectDAO = new DialectDAOHibernate(em);
        tonedCodePointDAO = new TonedCodePointDAOHibernate(em);
        tonedTranscriptionDAO = new TonedTranscriptionDAOHibernate(em);
        transcriptionSystemDAO = new TranscriptionSystemDAOHibernate(em);
        untonedCodePointDAO = new UntonedCodePointDAOHibernate(em);
        untonedTranscriptionDAO = new UntonedTranscriptionDAOHibernate(em);
    }

    public static DAOUtils getInstance() {
        return instance;
    }

    public EntityTransaction getTransaction() {
        return em.getTransaction();
    }

    public void clear() {
        em.clear();
    }

    public UnihanRowDAO getUnihanRowDAO() {
        return unihanRowDAO;
    }

    public CedictDAO getCedictDAO() {
        return cedictDAO;
    }

    /**
     * @return the dialectDAO
     */
    public DialectDAOHibernate getDialectDAO() {
        return dialectDAO;
    }

    /**
     * @return the tonedCodePointDAO
     */
    public TonedCodePointDAOHibernate getTonedCodePointDAO() {
        return tonedCodePointDAO;
    }

    /**
     * @return the tonedTranscriptionDAO
     */
    public TonedTranscriptionDAOHibernate getTonedTranscriptionDAO() {
        return tonedTranscriptionDAO;
    }

    /**
     * @return the transcriptionSystemDAO
     */
    public TranscriptionSystemDAOHibernate getTranscriptionSystemDAO() {
        return transcriptionSystemDAO;
    }

    /**
     * @return the untonedCodePointDAO
     */
    public UntonedCodePointDAOHibernate getUntonedCodePointDAO() {
        return untonedCodePointDAO;
    }

    /**
     * @return the untonedTranscriptionDAO
     */
    public UntonedTranscriptionDAOHibernate getUntonedTranscriptionDAO() {
        return untonedTranscriptionDAO;
    }

}
